﻿using Model;
using Presenters.WPF;
using Presenters.WPF.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Subject
{
    /// <summary>
    /// Lógica de interacción para HorarySolution.xaml
    /// </summary>
    public partial class HorarySolution : Window//, IHorarySolution
    {
        //HorarySolutionPresenter presenter;
        private string Message;
        private Horary horary;
        private bool useEmptyTextBox = true;

        public HorarySolution()
        {
            InitializeComponent();
            //presenter = new HorarySolutionPresenter(this);

        }
        public HorarySolution(Horary horary)
        {
            InitializeComponent();
            this.horary = horary;
            this.ListBox_Days.SelectedIndex = 0;
            //presenter = new HorarySolutionPresenter(this);           
        }

        //public int daySelected
        //{
        //    get { return this.ListBox_Days.SelectedIndex; }
        //}
        //public string message
        //{
        //    set { this.Message = value; }
        //}        

        private void TextBox_SearchCourse(object sender, TextChangedEventArgs e)
        {
            if (useEmptyTextBox == true)
            {
                TextBox TB_Selected = (TextBox)sender;
                if (TB_Selected != null)
                {
                    string auxiliar = TB_Selected.Text;
                    auxiliar = auxiliar.Replace("+", "");

                    if (auxiliar == TB_Selected.Text)
                    {
                        Model.Classroom RECETA = new Model.Classroom { code = TB_Selected.Text };
                        SearchCourse_Horary addCourse = new SearchCourse_Horary(RECETA, TB_Selected);
                        if (addCourse.execute == true)
                        {
                            if (String.IsNullOrEmpty(TB_Selected.Text))
                            {
                                horary.Remove(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(Convert.ToInt32(TB_Selected.Name.Replace("TextBox_", ""))));
                            }
                            else
                            {
                                addCourse.ShowDialog();
                                horary.listHoraryDays.Add(new HoraryDay(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(Convert.ToInt32(TB_Selected.Name.Replace("TextBox_", ""))), TB_Selected.Text));
                            }
                        }
                    }
                }
            }
        }

        private void Button_Click_Close(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        //private void Button_Click_Save(object sender, RoutedEventArgs e)
        //{
        //    horary = presenter.SaveHorary();
        //    MessageBox.Show(Message, "Información", MessageBoxButton.OK, MessageBoxImage.Information);  
        //}

        private void ListBox_SelectedItem(object sender, MouseButtonEventArgs e)
        {
            ListBox auxiliar_TextBox = (ListBox)sender;
            ListBoxItem auxiliar_TextBoxItem = (ListBoxItem)auxiliar_TextBox.SelectedItem;
            if (auxiliar_TextBoxItem != null)
            {
                this.GroupBox_Day.Header = auxiliar_TextBoxItem.Content;

                this.useEmptyTextBox = false;
                this.TextBox_7.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(7));
                this.TextBox_8.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(8));
                this.TextBox_9.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(9));
                this.TextBox_10.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(10));
                this.TextBox_11.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(11));
                this.TextBox_12.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(12));
                this.TextBox_13.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(13));
                this.TextBox_14.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(14));
                this.TextBox_15.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(15));
                this.TextBox_16.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(16));
                this.TextBox_17.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(17));
                this.TextBox_18.Text = horary.getCodCourse(horary.getDayFromInt(this.ListBox_Days.SelectedIndex), horary.getHoursFromInt(18));
                this.useEmptyTextBox = true;
            }
        }
    }
}
